package com.asset.dispoal.file.clouddesk.service.command;

import com.asset.dispoal.file.clouddesk.dto.CloudDeskDelRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.file.FileUtil;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.io.File;

@Component
@Slf4j
public class CloudDeskDeleteCommand implements BaseCommand<CloudDeskDelRequest, Result> {
    @Autowired
    private Environment environment;

    @Override
    public Result execute(CloudDeskDelRequest request) {
        String headUrl = environment.getProperty("file.evidence.url");
        String cloudDeskFolder = environment.getProperty("file.cloudDesk.url");
        String strBuilder = headUrl +
                File.separator +
                cloudDeskFolder +
                File.separator +
                request.getAssetInstBatchId() +
                File.separator +
                request.getName();
        FileUtil.delete(new File(strBuilder));
        return Result.ok();
    }
}
